package baseclasses;

import java.text.DecimalFormat;

import android.content.Context;


public class Grade {
	//static final string used for passing grade IDs to activities through intents
	public static final String GRADE_ID = "GRADE_ID";
	
	private int id;
	private int assignment_id;
	private String name;
	private int courseId;
	
	//grading is done by points and calculated to a percentage
	private double pointsEarned; 
	private double pointsOutof;
	private double percentage;
	private DecimalFormat df = new DecimalFormat("#.##"); //GPA format
	
	public Grade(){} //default constructor
	
	public Grade(int id, String name, int courseId, double pointsEarned,
			double pointsOutof) {	//Cons. used if accessed from Course/AssignView class
		super();
		this.id = id;
		this.name = name;
		this.assignment_id = -1;
		this.courseId = courseId;
		this.pointsEarned = pointsEarned;
		this.pointsOutof = pointsOutof;
		this.percentage = this.pointsEarned/this.pointsOutof*100;
	}
	
	public Grade(String name, int courseId, double pointsEarned,
			double pointsOutof) {	//cons. used if created from Course class
		super();
		this.name = name;
		this.assignment_id = -1;
		this.courseId = courseId;
		this.pointsEarned = pointsEarned;
		this.pointsOutof = pointsOutof;
		this.percentage = this.pointsEarned/this.pointsOutof*100;
	}
	
	public Grade(int id, int assignment_id, String name, int courseId, double pointsEarned,
			double pointsOutof) {	//Used if edited from assignment classes
		super();
		this.id = id;
		this.assignment_id = assignment_id;
		this.name = name;
		this.courseId = courseId;
		this.pointsEarned = pointsEarned;
		this.pointsOutof = pointsOutof;
		this.percentage = this.pointsEarned/this.pointsOutof*100;
	}
	
	public Grade(String name, int assignment_id, int courseId, double pointsEarned,
			double pointsOutof) {	//used if created from assignment course class
		super();
		this.assignment_id = assignment_id;
		this.name = name;
		this.courseId = courseId;
		this.pointsEarned = pointsEarned;
		this.pointsOutof = pointsOutof;
		this.percentage = this.pointsEarned/this.pointsOutof*100;
	}
	

	public int getAssignment_id() {
		return assignment_id;
	}

	public void setAssignment_id(int assignment_id) {
		this.assignment_id = assignment_id;
	}

	public int getId() {
		return id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getCourseId() {
		return courseId;
	}

	public void setCourseId(int courseId) {
		this.courseId = courseId;
	}

	public double getPointsEarned() {
		return pointsEarned;
	}

	public void setPointsEarned(double pointsEarned) {
		this.pointsEarned = pointsEarned;
	}

	public double getPointsOutof() {
		return pointsOutof;
	}

	public void setPointsOutof(double pointsOutof) {
		this.pointsOutof = pointsOutof;
	}

	public double getPercentage() {
		if(percentage!=pointsEarned/pointsOutof*100){ //recalculate if need be
			percentage = pointsEarned/pointsOutof*100;
		}
		return percentage;
	}

	public void setPercentage(double percentage) {
		this.percentage = percentage;
	}
	
	//returns a string containing the points earned, points out of, and percentage
  	//in a comprehensible format for the ViewGrades class		
	public String getGradeString(Context context){
		return pointsEarned+" / "+pointsOutof+"     "+df.format(getPercentage())+"%";
	}
	
	@Override
	public String toString(){
		return name;
	}
	
	
}